<html>
<head><meta charset="utf-8"><title>design note lang-team#71 · t-lang · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/index.html">t-lang</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/design.20note.20lang-team.2371.html">design note lang-team#71</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="241296919"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/design%20note%20lang-team%2371/near/241296919" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/design.20note.20lang-team.2371.html#241296919">(Jun 02 2021 at 18:08)</a>:</h4>
<p>Opening this topic to follow up with <span class="user-mention" data-user-id="295632">@Diggsey</span></p>



<a name="241296950"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/design%20note%20lang-team%2371/near/241296950" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/design.20note.20lang-team.2371.html#241296950">(Jun 02 2021 at 18:09)</a>:</h4>
<p>I was saying that we were looking for a different term from Thunk, and they asked if I had a term in mind :)</p>



<a name="241296978"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/design%20note%20lang-team%2371/near/241296978" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/design.20note.20lang-team.2371.html#241296978">(Jun 02 2021 at 18:09)</a>:</h4>
<p>I think that for me I strongly associate "thunk" with lazy evaluation, though it's also used in many ways</p>



<a name="241297051"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/design%20note%20lang-team%2371/near/241297051" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/design.20note.20lang-team.2371.html#241297051">(Jun 02 2021 at 18:09)</a>:</h4>
<p>I'd probably call this case -- adapting or putting advice around a function -- a "shim" but I don't think that's a standard terminology</p>



<a name="241297075"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/design%20note%20lang-team%2371/near/241297075" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/design.20note.20lang-team.2371.html#241297075">(Jun 02 2021 at 18:09)</a>:</h4>
<p>maybe just "adapter thunk"?</p>



<a name="241297138"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/design%20note%20lang-team%2371/near/241297138" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/design.20note.20lang-team.2371.html#241297138">(Jun 02 2021 at 18:10)</a>:</h4>
<p><span class="user-mention" data-user-id="127859">@Taylor Cramer</span> did you have an alternate suggestion?</p>



<a name="241297209"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/design%20note%20lang-team%2371/near/241297209" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/design.20note.20lang-team.2371.html#241297209">(Jun 02 2021 at 18:10)</a>:</h4>
<p>I also mentioned that it'd be great to have some examples of how such a function could be used</p>



<a name="241297459"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/design%20note%20lang-team%2371/near/241297459" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Diggsey <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/design.20note.20lang-team.2371.html#241297459">(Jun 02 2021 at 18:12)</a>:</h4>
<p>Yeah, I can come up with an example - I guess it depends how "real" you want :)</p>



<a name="241297524"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/design%20note%20lang-team%2371/near/241297524" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/design.20note.20lang-team.2371.html#241297524">(Jun 02 2021 at 18:12)</a>:</h4>
<p>I think one aspect of it is that it's not definitively clear to me that the majority of the solution space being explored is centered around specifically shims/trampolines/thunks, but rather somehow "calling a function type" (rather than a function value). I might be wrong about this notion though, it's not fully formed.</p>



<a name="241297527"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/design%20note%20lang-team%2371/near/241297527" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Diggsey <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/design.20note.20lang-team.2371.html#241297527">(Jun 02 2021 at 18:12)</a>:</h4>
<p>a lot of the practical cases involve interactions with obscure C APIs...</p>



<a name="241297680"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/design%20note%20lang-team%2371/near/241297680" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/design.20note.20lang-team.2371.html#241297680">(Jun 02 2021 at 18:13)</a>:</h4>
<p>I think having at least one really practical example for this note in particular, even if that means "with this particular c library", is very good</p>



<a name="241297989"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/design%20note%20lang-team%2371/near/241297989" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/design.20note.20lang-team.2371.html#241297989">(Jun 02 2021 at 18:14)</a>:</h4>
<p>that would indeed be helpful</p>



<a name="241298029"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/design%20note%20lang-team%2371/near/241298029" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/design.20note.20lang-team.2371.html#241298029">(Jun 02 2021 at 18:14)</a>:</h4>
<p>I agree with trampoline as a possible name too, although I tend to think of that as a function that takes a fn pointer and calls it</p>



<a name="241298068"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/design%20note%20lang-team%2371/near/241298068" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/design.20note.20lang-team.2371.html#241298068">(Jun 02 2021 at 18:14)</a>:</h4>
<p>yeah, this is why I feel like it's not really about function values to some extent</p>



<a name="241298106"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/design%20note%20lang-team%2371/near/241298106" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/design.20note.20lang-team.2371.html#241298106">(Jun 02 2021 at 18:15)</a>:</h4>
<p>"static thunk"</p>



<a name="241298416"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/design%20note%20lang-team%2371/near/241298416" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/design.20note.20lang-team.2371.html#241298416">(Jun 02 2021 at 18:17)</a>:</h4>
<p>"derived functions"?</p>



<a name="241298430"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/design%20note%20lang-team%2371/near/241298430" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/design.20note.20lang-team.2371.html#241298430">(Jun 02 2021 at 18:17)</a>:</h4>
<p>(it's one function that is <em>derived</em> from another)</p>



<a name="241298455"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/design%20note%20lang-team%2371/near/241298455" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/design.20note.20lang-team.2371.html#241298455">(Jun 02 2021 at 18:18)</a>:</h4>
<p>"advised functions"? (referencing AOT)</p>



<a name="241298495"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/design%20note%20lang-team%2371/near/241298495" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Diggsey <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/design.20note.20lang-team.2371.html#241298495">(Jun 02 2021 at 18:18)</a>:</h4>
<p>at least to me, all of these - "thunks", "trampolines" etc are implied to be static - I've only ever seen this terminology used with compiler-generated code, where the compiler knows the address of the target function, and it's generating a "trampoline" that's specific to that function</p>



<a name="241298562"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/design%20note%20lang-team%2371/near/241298562" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Diggsey <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/design.20note.20lang-team.2371.html#241298562">(Jun 02 2021 at 18:18)</a>:</h4>
<p>if the target function was passed in, then the thunk/trampoline/etc wouldn't be needed in the first place</p>



<a name="241298831"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/design%20note%20lang-team%2371/near/241298831" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Diggsey <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/design.20note.20lang-team.2371.html#241298831">(Jun 02 2021 at 18:20)</a>:</h4>
<p>(because that code could just live in a library, it wouldn't need to be generated by the compiler)</p>



<a name="241299350"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/design%20note%20lang-team%2371/near/241299350" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/design.20note.20lang-team.2371.html#241299350">(Jun 02 2021 at 18:24)</a>:</h4>
<p>I'm ok with thunks, although I agree with the sentiment that this doesn't quite <em>feel</em> like what I think of as a thunk, which remains a kind of "continuation"</p>



<a name="241299384"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/design%20note%20lang-team%2371/near/241299384" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/design.20note.20lang-team.2371.html#241299384">(Jun 02 2021 at 18:24)</a>:</h4>
<p>How do you feel about the term trampoline, <span class="user-mention" data-user-id="295632">@Diggsey</span> ?</p>



<a name="241299432"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/design%20note%20lang-team%2371/near/241299432" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/design.20note.20lang-team.2371.html#241299432">(Jun 02 2021 at 18:25)</a>:</h4>
<p><a href="https://en.wikipedia.org/wiki/Trampoline_(computing)">https://en.wikipedia.org/wiki/Trampoline_(computing)</a></p>



<a name="241299458"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/design%20note%20lang-team%2371/near/241299458" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/design.20note.20lang-team.2371.html#241299458">(Jun 02 2021 at 18:25)</a>:</h4>
<blockquote>
<p>As used in some Lisp implementations, a trampoline is a loop that iteratively invokes thunk-returning functions (continuation-passing style). A single trampoline suffices to express all control transfers of a program; a program so expressed is trampolined, or in trampolined style; converting a program to trampolined style is trampolining. Programmers can use trampolined functions to implement tail-recursive function calls in stack-oriented programming languages.[1]</p>
</blockquote>



<a name="241299463"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/design%20note%20lang-team%2371/near/241299463" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/design.20note.20lang-team.2371.html#241299463">(Jun 02 2021 at 18:25)</a>:</h4>
<p>this is the usage I am thinking of</p>



<a name="241299492"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/design%20note%20lang-team%2371/near/241299492" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/design.20note.20lang-team.2371.html#241299492">(Jun 02 2021 at 18:25)</a>:</h4>
<blockquote>
<p>When interfacing pieces of code with incompatible calling conventions, a trampoline is used to convert the caller's convention into the callee's convention.</p>
</blockquote>



<a name="241299499"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/design%20note%20lang-team%2371/near/241299499" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/design.20note.20lang-team.2371.html#241299499">(Jun 02 2021 at 18:25)</a>:</h4>
<p>but this seems very similar</p>



<a name="241299931"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/design%20note%20lang-team%2371/near/241299931" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/design.20note.20lang-team.2371.html#241299931">(Jun 02 2021 at 18:28)</a>:</h4>
<p>I'd be happy with trampoline</p>



<a name="241313541"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/design%20note%20lang-team%2371/near/241313541" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/design.20note.20lang-team.2371.html#241313541">(Jun 02 2021 at 20:15)</a>:</h4>
<p>I'm honestly fine with thunks, as long as there's a clear definition and example that includes "how is this called".</p>



<a name="241315589"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/design%20note%20lang-team%2371/near/241315589" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Daniel Henry-Mantilla <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/design.20note.20lang-team.2371.html#241315589">(Jun 02 2021 at 20:31)</a>:</h4>
<p>FWIW: I personally find trampoline or generic shim to match best the idea of deriving a function out of another, <em>with no captures</em> / environment involved. Thunk makes me think of a <code>dyn</code> closure (with a pinch of boxing), I don't know why <span aria-label="sweat smile" class="emoji emoji-1f605" role="img" title="sweat smile">:sweat_smile:</span></p>



<a name="241319357"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/design%20note%20lang-team%2371/near/241319357" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Diggsey <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/design.20note.20lang-team.2371.html#241319357">(Jun 02 2021 at 21:01)</a>:</h4>
<p>I'm happy with either</p>



<a name="241450989"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/design%20note%20lang-team%2371/near/241450989" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Diggsey <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/design.20note.20lang-team.2371.html#241450989">(Jun 03 2021 at 20:51)</a>:</h4>
<p>I updated the PR with the suggestions and added an example.</p>



<a name="245084011"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/design%20note%20lang-team%2371/near/245084011" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/design.20note.20lang-team.2371.html#245084011">(Jul 06 2021 at 19:01)</a>:</h4>
<p><span class="user-mention" data-user-id="295632">@Diggsey</span> awesome, sorry for the radio silence! returning to this now</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>